﻿using System.Web.Mvc;
using System.Web.Routing;

namespace Journal.Common.Helpers.HtmlControls
{
    public static class ContainerControl
    {
        public static TagBuilder FormContainerControl(this HtmlHelper html, string containerContent, string cssClass)
        {
            TagBuilder container = Container(containerContent, cssClass);
            return container;
        }

        public static TagBuilder FormContainerControl(this HtmlHelper html, string containerContent, string cssClass, object htmlAttributes)
        {
            TagBuilder container = Container(containerContent, cssClass);
            container.MergeAttributes(new RouteValueDictionary(htmlAttributes));
            return container;
        }

        private static TagBuilder Container(string containerContent, string cssClass)
        {
            TagBuilder tagBuilder = new TagBuilder("div");
            if (!string.IsNullOrEmpty(cssClass))
            {
                tagBuilder.AddCssClass(cssClass);
            }

            tagBuilder.InnerHtml += containerContent;
            return tagBuilder;
        }
    }
}